package jorm;

import java.sql.*;
import java.util.List;

/**
 * @auther:陈磊 <br/>
 * Date: 12-12-29<br/>
 * Time: 下午5:00<br/>
 * connectMethod:13638363871@163.com<br/>
 */
public interface IOperations {
    /**
     * 获取连接
     * @return
     */
    Connection getConnection();

    /**
     * 关闭连接
     * @return
     */
    void close(Connection connection);
    void close(Statement st, Connection conn);
    void close(ResultSet rs, Statement st, Connection conn);

    /**
     * 更新数据
     * @param sql
     * @return
     */
    int update(String sql);

    /**
     * update
     * @param conn
     * @param sql
     * @param paras
     * @return
     * @throws java.sql.SQLException
     */
    int update(Connection conn, String sql, Object... paras)throws SQLException;
    /**
     * Delete record by id.
     * Example: boolean succeed = Db.deleteById("user", "user_id", 15);
     * @param tableName the table name of the table
     * @param primaryKey the primary key of the table
     * @param id the id value of the record
     * @return true if delete succeed otherwise false
     */
    boolean deleteById(String tableName, String primaryKey, Object id);

    /**
     * delete
     * @param conn
     * @param sql
     * @param paras
     * @return
     */
    boolean delete(Connection conn, String sql, Object... paras) throws SQLException;


    /**
     *
     * @param conn
     * @param sql
     * @param paras
     */
    void insert(Connection conn, String sql, Object... paras) throws SQLException;

    public void fillPreparedStatement(PreparedStatement pst, Object... paras);

    List<Record> select(String sql);

    List<Record> select(String sql, Object... paras);

}
